<template>
  <!--会签管理-审批设置-->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目">
              <a-select :options="levelOneOptions" placeholder="请选择项目" v-model="queryParam.projectId">
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据名称">
              <a-input placeholder="请输入" v-model="queryParam.billsTemplateName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据类型">
              <!-- <a-select style="width: 100px;" placeholder="请选择" v-model="queryParam.billsType">
                <a-select-option value="1">人事</a-select-option>
                <a-select-option value="2">行政</a-select-option>
                <a-select-option value="3">财务</a-select-option>
                <a-select-option value="4">合同</a-select-option>
              </a-select> -->
              <j-dict-select-tag placeholder="请选择单据类型" v-model="queryParam.billsType"
                dictCode="bills_type"></j-dict-select-tag>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--              <a @click="handleToggleSearch" style="margin-left: 8px">
                  {{ toggleSearchStatus ? '收起' : '展开' }}
                  <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
                </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdds('add')" style="background-color:#32cd99;color: white;">新增审批模板</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>-->

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
            style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="isLeadership" slot-scope="text,record">
          <div>{{record.isLeadership == '1'?'是':record.isLeadership == '0'?'否':''}}</div>
        </template>
        <template slot="status" slot-scope="text,record">
          <a-switch :checked="record.status === '1' ? true:false" @change="updata($event,record)"/>
        </template>
        <template slot="action" slot-scope="text, record">
          <a @click="handleAdds('edit',record)" v-if="record.status === '1' ? false:true">编辑 </a>
          <a-divider type="vertical" v-if="record.status === '1' ? false:true"/>
          <a @click="handleSheZhi(record,'edit')" v-if="record.status === '1' ? false:true">设置 </a>
          <a-divider type="vertical" v-if="record.status === '1' ? false:true"/>
          <a @click="handleSheZhi(record,'detail')">预览 </a>
        </template>
      </a-table>
    </div>

    <wt-shezhiaddshenpi-modal ref="modalForm" :id="id" @ok="modalFormOk"></wt-shezhiaddshenpi-modal>
    <wt-shezhi-modal ref="modalForm2" :id="id" @ok="modalFormOk" @handleAddZur="handleAddZur" @handleDelete="handleDeletes" :pageType="pageType"></wt-shezhi-modal>
    <wt-shezhiaddshenpiren-modal ref="modalForm3" :id="id" @ok="handleSheZhi"></wt-shezhiaddshenpiren-modal>
    <!-- <wt-shezhicailiao-modal ref="modalForm1" :id="id" @ok="modalFormOk"></wt-shezhicailiao-modal>
      <wt-shezhilaowu-modal ref="modalForm2" :id="id" @ok="modalFormOk"></wt-shezhilaowu-modal>
      <wt-shezhifukuan-modal ref="modalForm3" :id="id" @ok="modalFormOk"></wt-shezhifukuan-modal> -->

  </a-card>
</template>

<script>
  import {
    deleteAction,
    httpAction,
    getAction
  } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import {
    mixinDevice
  } from '@/utils/mixin'
  import {
    JeecgListMixin
  } from '@/mixins/JeecgListMixin'
  import WtShezhiaddshenpiModal from './modules/WtShezhiaddshenpiModal'
  import WtShezhiaddshenpirenModal from './modules/WtShezhiaddshenpirenModal'
  import WtShezhiModal from './modules/WtShezhiModal'
  import WtShezhicailiaoModal from './modules/WtShezhicailiaoModal'
  import WtShezhilaowuModal from './modules/WtShezhilaowuModal'
  import WtShezhifukuanModal from './modules/WtShezhifukuanModal'
  
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'

  export default {
    name: 'WtBrandList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      WtShezhiaddshenpiModal,
      WtShezhiaddshenpirenModal,
      WtShezhiModal,
      WtShezhicailiaoModal,
      WtShezhilaowuModal,
      WtShezhifukuanModal,
      JDictSelectTag
    },
    data() {
      return {
        description: '品牌记录表管理页面',
        // 表头
        columns: [{
            title: '项目',
            align: "center",
            dataIndex: 'projectName'
          },
          {
            title: '单据名称',
            align: "center",
            dataIndex: 'billsTemplateName'
          },
          {
            title: '模板名称',
            align: "center",
            dataIndex: 'billsType_dictText'
          },
          {
            title: '单据模板',
            align: "center",
            dataIndex: 'receiptsModel_dictText'
          },
          {
            title: '是否需要部门领导审核',
            align: "center",
            dataIndex: 'isLeadership',
            scopedSlots: {
              customRender: 'isLeadership'
            }
          }, 
          {
            title: '审批层级',
            align: "center",
            dataIndex: 'approveHierarchy'
          }, {
            title: '状态开启',
            align: "center",
            dataIndex: 'status',
            scopedSlots: {
              customRender: 'status'
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            fixed: "right",
            width: 147,
            scopedSlots: {
              customRender: 'action'
            }
          }
        ],
        sel_obj:{},
        url: {
          list: "/countersign/wtCountersignTemplate/list",
          list2:'/countersign/wtCountersignTemplateProcess/getList',
          delete: "/wtBrand/delete",
          delete2: "/countersign/wtCountersignTemplateProcess/delete", //
          deleteBatch: "/wtBrand/deleteBatch",
          exportXlsUrl: "/wtBrand/exportXls",
          importExcelUrl: "wtBrand/importExcel",

        },
        dictOptions: {},
        superFieldList: [],
        levelOneOptions: [],
        treeData1: [],
        pageType:'',
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleAdds(type,record){
        this.$refs.modalForm.pageType = type;
        if(type === 'add'){
          this.$refs.modalForm.add();
          this.$refs.modalForm.title = "新增审批模板"; 
        }else if(type === 'edit'){
          this.$refs.modalForm.edit(record);
          this.$refs.modalForm.title = "编辑审批模板"; 
        }
      },
      updata(val,record){
        console.log(1,val,record);
        let that = this;
        let params = {
          id:record.id,
          status:val === true?'1':'0'
        }
        httpAction('/countersign/wtCountersignTemplate/edit', params, 'POST')
          .then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              this.loadData();
            } else {
              that.$message.warning(res.message)
            }
          })
      },
      handleSheZhi: function(record,type) {
        console.log(11,record)
        let params = {templateId:''}
        if(!!record){
          this.sel_obj = record;
          params.templateId = record.id;
        }else{
          params.templateId = this.sel_obj.id;
        }
        
        getAction(this.url.list2, params).then((res) => {
          if (res.success) {
            let obj = res.result;
            this.$refs.modalForm2.edit(obj);
            if(!!type){
              this.pageType = type;
            }
            if(type === 'eidt'){
              this.$refs.modalForm2.title = "审批流程设置";
            }else if(type === 'detail'){
              this.$refs.modalForm2.title = "审批流程设置详情";
            }
            this.$forceUpdate();
          } else {
            this.$message.warning(res.message);
            //this.$refs.modalForm2.add();
            //this.$refs.modalForm2.title = "审批流程设置";
          }
          
        })
        
        // this.$refs.modalForm.disableSubmit = true;
      },
      handleDeletes(record){
        console.log(1111,record)
        var that = this;
        that.loading = true;
        deleteAction(that.url.delete2, {id: record}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.handleSheZhi();
          } else {
            that.$message.warning(res.message);
          }
        }).finally(() => {
          that.loading = false;
        });
      },
      handleSheZhiCailiao: function(record) {
        this.$refs.modalForm1.edit(record);
        this.$refs.modalForm1.title = "审批流程设置";

        // this.$refs.modalForm.disableSubmit = true;
      },
      handleSheZhilaowu: function(record) {
        this.$refs.modalForm2.edit(record);
        this.$refs.modalForm2.title = "审批流程设置";

        // this.$refs.modalForm.disableSubmit = true;
      },
      handleSheZhiFUkuan: function(record) {
        this.$refs.modalForm3.edit(record);
        this.$refs.modalForm3.title = "审批流程设置";

        // this.$refs.modalForm.disableSubmit = true;
      },
      handleAddZur(type,record){
        if(type === 'add'){
          this.$refs.modalForm3.add(type,this.sel_obj);
          this.$refs.modalForm3.title = "新增";
        }else if(type === 'edit'){
          this.$refs.modalForm3.edit(type,record,this.sel_obj);
          this.$refs.modalForm3.title = "编辑";
        }
        
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        var params = this.getQueryParams(); //查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result;
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            } else {
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
        getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
          if (res.success) {

            this.treeData1 = []
            let treeList1 = res.result
            for (let a = 0; a < treeList1.length; a++) {
              let temp = treeList1[a]
              temp.isLeaf = temp.leaf
              this.treeData1.push(temp)
            }

            this.levelOneOptions = [...this.treeData1].map((v) => {
              return {
                ...v,
                value: v.id,
                label: v.departName,
              }
            })


          }
        })
      },
      initDictConfig() {},
      getSuperFieldList() {
        let fieldList = [];
        fieldList.push({
          type: 'string',
          value: 'categoryOneId',
          text: '一级分类id',
          dictCode: ''
        })
        fieldList.push({
          type: 'string',
          value: 'categoryTwoId',
          text: '二级分类id',
          dictCode: ''
        })
        fieldList.push({
          type: 'string',
          value: 'categoryThreeId',
          text: '三级分类id',
          dictCode: ''
        })
        fieldList.push({
          type: 'string',
          value: 'name',
          text: '名称',
          dictCode: ''
        })
        fieldList.push({
          type: 'string',
          value: 'introduce',
          text: '介绍',
          dictCode: ''
        })
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>